package com.source.hotelbath.utils;

import android.text.TextUtils;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.Locale;


public class DateUtils {
    private static SimpleDateFormat sf = null; //日期管理者

    /*获取系统时间 格式为："yyyy/MM/dd "*/
    public static String getCurrentDate() {
        Date d = new Date();
        sf = new SimpleDateFormat("yyyy年MM月dd日");
        return sf.format(d);
    }

    /*时间戳转换成字符窜*/
    public static String getDateToString(long time) {
        Date d = new Date(time);
        sf = new SimpleDateFormat("yyyy-MM-dd");
        return sf.format(d);
    }

    /*时间戳转换成字符窜*/
    public static String getDateToStringdian(long time) {
        // Date d = new Date(time);
        SimpleDateFormat sfs = new SimpleDateFormat("yyyy.MM.dd  HH:mm:ss");
        return sfs.format(new Date(time));
    }

    //经过验证只有这个能用，其他都不能用
    public static String getStrTime(String cc_time) {
        String re_StrTime = null;

        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        // 例如：cc_time=1291778220
        if (!TextUtils.isEmpty(cc_time)) {
            long lcc_time = Long.valueOf(cc_time);
            re_StrTime = sdf.format(new Date(lcc_time * 1000L));
        }


        return re_StrTime;

    }

    //经过验证只有这个能用，其他都不能用
    public static String getYTime(String cc_time) {
        String re_StrTime = null;

        SimpleDateFormat sdf = new SimpleDateFormat("yyyy");
        // 例如：cc_time=1291778220
        if (!TextUtils.isEmpty(cc_time)) {
            long lcc_time = Long.valueOf(cc_time);
            re_StrTime = sdf.format(new Date(lcc_time * 1000L));
        }


        return re_StrTime;

    }

    public static String getStrDay(String cc_time) {
        String re_StrTime = null;

        SimpleDateFormat sdf = new SimpleDateFormat("MM.dd");
        // 例如：cc_time=1291778220

        long lcc_time = Long.valueOf(cc_time);
        re_StrTime = sdf.format(new Date(lcc_time * 1000L));

        return re_StrTime;

    }

    /*时间戳转换成字符窜*/
    public static String getDateToStringdianzi(long time) {
        Date d = new Date(time);
        sf = new SimpleDateFormat("yyyy年MM月dd日HH:mm");
        return sf.format(d);
    }


    /*时间戳转换成字符窜*/
    public static String getDateToStringNoyear(long time) {
        Date d = new Date(time);
        sf = new SimpleDateFormat("MM-dd  HH:mm");
        return sf.format(d);
    }


    /**
     * 转成  00:00
     *
     * @param time
     * @return
     */
    public static String getDateToStringHourAndMinute(long time) {

        sf = new SimpleDateFormat("HH:mm");
        Date d = new Date(time);
        return sf.format(d);
    }

    /*将字符串转为时间戳*/
    public static long getStringToDate(String time) {
        sf = new SimpleDateFormat("yyyy年MM月dd日");
        Date date = new Date();
        try {
            date = sf.parse(time);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return date.getTime();
    }

    /*时间戳转换成字符窜*/
    public static String getDateToStringYue(long time) {
        Date d = new Date(time);
        sf = new SimpleDateFormat("yyyy年MM月");
        return sf.format(d);
    }

    public static long getStringToDateYue(String time) {
        sf = new SimpleDateFormat("yyyy年MM月");
        Date date = new Date();
        try {
            date = sf.parse(time);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return date.getTime();
    }

    public static String getDateToStringNian(long time) {
        Date d = new Date(time);
        sf = new SimpleDateFormat("yyyy");
        return sf.format(d);
    }

    public static String getDateCollectTime(long time) {
        Date d = new Date(time);
        sf = new SimpleDateFormat("yyyy-MM-dd");
        return sf.format(d);
    }

    public static String getCurrentTime(String format) {
        Date date = new Date();
        SimpleDateFormat sdf = new SimpleDateFormat(format, Locale.getDefault());
        String currentTime = sdf.format(date);
        return currentTime;
    }

    public static String getCurrentTime() {
        return getCurrentTime("yyyy-MM-dd  HH:mm:ss");
    }

    /**
     * 根据日期获取周几
     *
     * @param date
     * @return
     */
    public static String getWeekOfDate(long time) {
        Date date = new Date(time);
        String[] weekDaysName = {"周日", "周一", "周二", "周三", "周四", "周五", "周六"};
        String[] weekDaysCode = {"0", "1", "2", "3", "4", "5", "6"};
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        int intWeek = calendar.get(Calendar.DAY_OF_WEEK) - 1;
        return weekDaysName[intWeek];
    }

    public static long getTimeStemp(String time) throws ParseException {
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Date date = simpleDateFormat.parse(time);
        long timeStemp = date.getTime();

        return timeStemp;
    }

}